package com.softtown.modules.workflow.controller;

import com.github.pagehelper.PageInfo;
import com.softtown.common.annotation.LogOperation;
import com.softtown.common.exception.ErrorCode;
import com.softtown.common.utils.Result;
import com.softtown.modules.workflow.dto.SwfDocPhaseDefDTO;
import com.softtown.modules.workflow.dto.SwfDocPhaseDefPageDTO;
import com.softtown.modules.workflow.entity.SwfDocPhaseDefEntity;
import com.softtown.modules.workflow.service.SwfDocPhaseDefService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author: Dingyayong
 * @Date: 2019/8/22 17:38
 * @Description:
 */
@RestController
@RequestMapping("swf/docPhaseDef")
@Api(tags = "获取该公司各个模块审批段")
public class SwfDocPhaseDefController {

    @Resource
    private SwfDocPhaseDefService swfDocPhaseDefService;

    /**
     * 获取该公司出差申请审批段
     *
     * @param swfDocPhaseDefDTO 公司审批段DTO
     * @return com.softtown.common.utils.Result<java.util.List < com.softtown.modules.entity.SwfDocPhaseDefEntity>>
     * @Author Dingyayong
     * @Date 2020/4/13 16:56
     */
    @PostMapping("getDocPhaseDef")
    @ApiOperation("获取该公司出差申请审批段")
    @LogOperation("获取该公司出差申请审批段")
    public Result<List<SwfDocPhaseDefEntity>> getDocPhaseDef(@RequestBody SwfDocPhaseDefDTO swfDocPhaseDefDTO) {
        List<SwfDocPhaseDefEntity>
                swfDocPhaseDefEntity = swfDocPhaseDefService.getDocPhaseDef(swfDocPhaseDefDTO);
        return new Result<List<SwfDocPhaseDefEntity>>().ok(swfDocPhaseDefEntity);
    }

    /**
     * 获取该公司差旅报销审批段
     *
     * @param swfDocPhaseDefDTO 公司审批段DTO
     * @return com.softtown.common.utils.Result<java.util.List < com.softtown.modules.entity.SwfDocPhaseDefEntity>>
     * @Author Dingyayong
     * @Date 2020/4/13 16:57
     */
    @PostMapping("getTravelDocPhaseDef")
    @ApiOperation("获取该公司差旅报销审批段")
    @LogOperation("获取该公司差旅报销审批段")
    public Result<List<SwfDocPhaseDefEntity>> getTravelDocPhaseDef(@RequestBody SwfDocPhaseDefDTO swfDocPhaseDefDTO) {
        List<SwfDocPhaseDefEntity>
                swfDocPhaseDefEntity = swfDocPhaseDefService.getTravelDocPhaseDef(swfDocPhaseDefDTO);
        return new Result<List<SwfDocPhaseDefEntity>>().ok(swfDocPhaseDefEntity);
    }

    /**
     * 单据审批设置分页
     *
     * @param swfDocPhaseDefPageDTO 公司单据审批DTO
     * @return com.softtown.common.utils.Result
     * @Author Dingyayong
     * @Date 2020/4/13 17:00
     */
    @PostMapping("getDocPhaseDefList")
    @ApiOperation("单据审批设置分页")
    @LogOperation("单据审批设置分页")
    public Result getDocPhaseDefList(@RequestBody SwfDocPhaseDefPageDTO swfDocPhaseDefPageDTO) {
        PageInfo<SwfDocPhaseDefEntity> page = swfDocPhaseDefService.getDocPhaseDefList(swfDocPhaseDefPageDTO);
        return new Result<PageInfo<SwfDocPhaseDefEntity>>().ok(page);
    }

    /**
     * 检查单据审批设置里是否已有该单据类型的审批段
     *
     * @param swfDocPhaseDefDTO 公司审批段DTO
     * @return com.softtown.common.utils.Result
     * @Author Dingyayong
     * @Date 2020/4/13 17:02
     */
    @PostMapping("checkDocPhaseDef")
    @ApiOperation("检查单据审批设置里是否已有该单据类型的审批段")
    @LogOperation("检查单据审批设置里是否已有该单据类型的审批段")
    public Result checkDocPhaseDef(@RequestBody SwfDocPhaseDefDTO swfDocPhaseDefDTO) {
        Result result = new Result<>();
        List<SwfDocPhaseDefEntity> swfDocPhaseDefEntities
                = swfDocPhaseDefService.checkDocPhaseDef(swfDocPhaseDefDTO.getCompId(),swfDocPhaseDefDTO.getDocTypeValue());
        if (swfDocPhaseDefEntities.size() > 0) {
            return result.error(ErrorCode.DOC_TYPE_ERROR);
        }
        return result;
    }

    /**
     * 根据该公司单据类型获取审批段设置
     *
     * @param swfDocPhaseDefDTO 公司审批段DTO
     * @return com.softtown.common.utils.Result<java.util.List < com.softtown.modules.entity.SwfDocPhaseDefEntity>>
     * @Author Dingyayong
     * @Date 2020/4/13 17:02
     */
    @PostMapping("getDocPhaseDefByDocType")
    @ApiOperation("根据该公司单据类型获取审批段设置")
    @LogOperation("根据该公司单据类型获取审批段设置")
    public Result<List<SwfDocPhaseDefEntity>> getDocPhaseDefByDocType(@RequestBody SwfDocPhaseDefDTO swfDocPhaseDefDTO) {
        return new Result<List<SwfDocPhaseDefEntity>>().ok(swfDocPhaseDefService.getDocPhaseDefByDocType(swfDocPhaseDefDTO));
    }

    /**
     * 获取该公司借款申请审批段
     *
     * @param swfDocPhaseDefDTO
     * @return com.softtown.common.utils.Result<java.util.List < com.softtown.modules.entity.SwfDocPhaseDefEntity>>
     * @author fuming
     * @date 2019/10/29 11:08
     */
    @PostMapping("getAdvDocPhaseDef")
    @ApiOperation("获取该公司借款申请审批段")
    @LogOperation("获取该公司借款申请审批段")
    public Result<List<SwfDocPhaseDefEntity>> getAdvDocPhaseDef(@RequestBody SwfDocPhaseDefDTO swfDocPhaseDefDTO) {
        List<SwfDocPhaseDefEntity> advDocPhaseDef = swfDocPhaseDefService.getAdvDocPhaseDef(swfDocPhaseDefDTO);
        return new Result<List<SwfDocPhaseDefEntity>>().ok(advDocPhaseDef);
    }

    /**
     * 获取该公司费用申请审批段
     *
     * @param swfDocPhaseDefDTO
     * @return com.softtown.common.utils.Result<java.util.List < com.softtown.modules.entity.SwfDocPhaseDefEntity>>
     * @Author fuming
     * @Date 2019/12/19 18:24
     */
    @PostMapping("getGenlDocPhaseDef")
    @ApiOperation("获取该公司费用申请审批段")
    @LogOperation("获取该公司费用申请审批段")
    public Result<List<SwfDocPhaseDefEntity>> getGenlDocPhaseDef(@RequestBody SwfDocPhaseDefDTO swfDocPhaseDefDTO) {
        List<SwfDocPhaseDefEntity> swfDocPhaseDefEntities = swfDocPhaseDefService.selectGenlDocPhaseDef(swfDocPhaseDefDTO);
        return new Result<List<SwfDocPhaseDefEntity>>().ok(swfDocPhaseDefEntities);
    }
}
